package middleware

import (
	"cabinet/serializer"
	"cabinet/util"

	"github.com/gin-gonic/gin"
)

func JwtAuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		uid, err := util.TokenValid(c)
		if err != nil {
			c.String(serializer.CodeCheckLogin, err.Error())
			c.Abort()
			return
		}
		c.Set("user_id", uid)
		c.Next()
	}
}
